---
title: "plotly"
icon: "chart-pie"
description: ""
---

```python
plotly(fig, size: float = 1.0) -> Dict
```

The `plotly` function allows you to embed interactive Plotly charts into your application. It's a powerful way to visualize data dynamically and intuitively.

## Parameters

- **`fig`** _(Plotly figure object)_: The Plotly figure object to be rendered. This can be created using Plotly Express or the Plotly Graph Objects API.
- **`size`** _(float)_: _(Optional)_ The width of the component in a row. Defaults to `1.0` (full row). See the [Layout Guide](/layout/guide) for details.

<Frame>
<img
  className="block dark:hidden"
  src="/images/plotly.png"
  alt="Hero Light"
/>
</Frame>

## Returns

- `Dict` containing the full plotly component metadata and data.

## Usage Example

Here's a quick example demonstrating how to use the `plotly` function:

```python
from preswald import plotly
import plotly.express as px

# Create a scatter plot using Plotly Express
fig = px.scatter(x=[1, 2, 3], y=[4, 5, 6], labels={"x": "X-axis", "y": "Y-axis"})

# Embed the Plotly chart into your app
plotly(fig)
```

### Creating Plotly Charts

You can create a variety of charts using Plotly Express or Plotly Graph Objects, such as:

- Line charts
- Bar charts
- Scatter plots
- Pie charts
- Histograms
- 3D plots

Here's an example of a bar chart:

```python
from preswald import plotly
import plotly.express as px

# Data for the chart
data = {"Category": ["A", "B", "C"], "Values": [10, 20, 30]}
fig = px.bar(data, x="Category", y="Values", title="Sample Bar Chart")

# Embed the bar chart
plotly(fig)
```

### Why Use `plotly`?

- **Interactivity**: Zoom, pan, hover, and more
- **Customization**: Tailor every aspect of the chart to suit your needs
- **Versatility**: Supports a wide range of visualizations

Visualize your data like never before with Plotly! 🌟
